﻿using LJ.Abstractions.Config;
using Microsoft.Extensions.Options;

namespace LJ.Host.Abstractions.Config;

public class ConfigProvider(IServiceProvider serviceProvider) : IConfigProvider
{
    private readonly IServiceProvider _serviceProvider = serviceProvider;

    public TConfig Get<TConfig>(string key) where TConfig : class
    {
        return _serviceProvider.GetRequiredService<IOptionsMonitor<TConfig>>().Get(key);
    }

    public TConfig Get<TConfig>() where TConfig : class
    {
        return _serviceProvider.GetRequiredService<IOptionsMonitor<TConfig>>().CurrentValue;
    }
}
